package com.xyzwps.paimon.furina.modules.userinfo.service

import com.xyzwps.paimon.furina.infra.keyBy
import com.xyzwps.paimon.furina.modules.userinfo.entity.UserInfoRepository
import com.xyzwps.paimon.furina.modules.userinfo.entity.UserInfoSummary
import org.springframework.stereotype.Service

@Service
class UserInfoService(private val userInfoRepository: UserInfoRepository) {

    fun findSummaryById(id: Long): UserInfoSummary? = userInfoRepository.findByUserId(id)?.let { UserInfoSummary(it) }

    fun findIdToSummaryByIds(ids: Collection<Long>): Map<Long, UserInfoSummary> {
        if (ids.isEmpty()) return emptyMap()

        return userInfoRepository.findByUserIds(ids)
            .map { UserInfoSummary(it) }
            .keyBy { it.userId }
    }

}